package com.hotel.controllers;

import com.hotel.entitys.RestPOJO;
import com.hotel.entitys.RoomType;
import com.hotel.services.RoomTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author chend
 * @time 2022/02/28 14:28:10
 */
@RestController
@Api(tags="房间类型管理接口")//tags:说明信息
public class RoomTypeController {
    @Autowired
    private RoomTypeService roomTypeService ;

    @ApiOperation(
            value = "模态框查询所有房间类型",
            httpMethod = "GET",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    @GetMapping("/roomtype")
    public RestPOJO selAllType(){
          List<RoomType> typeList =  roomTypeService.selAllType();

        RestPOJO restPOJO = new RestPOJO();
        if (typeList.size()>=0){
            restPOJO.setMessage("查询成功");
            restPOJO.setStatus(1000);
            restPOJO.setData(typeList);
        }else {

            restPOJO.setMessage("查询失败");
            restPOJO.setStatus(1001);
        }
        return restPOJO ;
    }

    @ApiOperation(
            value = "添加房间类型",
            httpMethod = "POST",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    @PostMapping("/addType")
    public RestPOJO addType(@RequestBody RoomType roomType){
        Integer i = roomTypeService.addType(roomType);
        RestPOJO restPOJO = new RestPOJO();
        if (i>0){
            restPOJO.setMessage("增加成功");
            restPOJO.setStatus(1000);
        }else {
            restPOJO.setMessage("增加失败");
            restPOJO.setStatus(1001);
        }
        return restPOJO ;
    }

    @ApiOperation(
            value = "删除房间类型通过类型id",
            httpMethod = "GET",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    @GetMapping("/delByIdr")
    public RestPOJO delById(Integer type_id){
           Integer i = roomTypeService.delById(type_id);
        RestPOJO restPOJO = new RestPOJO();
        if (i>0){
            restPOJO.setMessage("删除成功");
            restPOJO.setStatus(1000);
        }else {
            restPOJO.setMessage("删除失败");
            restPOJO.setStatus(1001);
        }
        return restPOJO ;
    }

    @ApiOperation(
            value = "修改房间类型",
            httpMethod = "POST",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    @PostMapping("/setType")
    public RestPOJO setType(@RequestBody RoomType roomType) {
        Integer i = roomTypeService.setType(roomType);
        RestPOJO restPOJO = new RestPOJO();
        if (i>0){
            restPOJO.setMessage("修改成功");
            restPOJO.setStatus(1000);
        }else {
            restPOJO.setMessage("修改失败");
            restPOJO.setStatus(1001);
        }
        return restPOJO ;
    }

    @ApiOperation(
            value = "查询房间类型通过类型id",
            httpMethod = "GET",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    @GetMapping("/selTypeById")
    public RestPOJO selTypeById(Integer type_id){
           RoomType roomType = roomTypeService.selTypeById(type_id);
            RestPOJO restPOJO = new RestPOJO();
           if(roomType!=null){
               restPOJO.setMessage("查询成功");
               restPOJO.setStatus(1000);
               restPOJO.setData(roomType);
           }else {
               restPOJO.setMessage("查询失败");
               restPOJO.setStatus(1001);
           }
        return restPOJO;
    }
}
